<!-- <template>
	<view>
		<view class="boxtop">
			<text class="text">{{title}}</text>
			<button v-show="show" style="margin-right: 0;" size="mini" @click="delect(list.wid)">删除</button>
		</view>
		<hr>
		<view class="boxhead">
			<view class="item">
				<text class="text">仓库编号:</text>
				<text class="text1">{{list.wid}}</text>
			</view><hr>
			<view class="item">
				<text class="text">仓库名称:</text>
				<input type="text1" :disabled="dis" class="text1" v-model="list.wname">
			</view><hr>
			<view class="item">
				<text class="text">仓库负责人:</text>
				<text class="text2">{{dptemname}}</text>
				<select v-show="show" v-model="select">
					<option disabled value="">请选择</option>
					<option v-for="dept in options" :key="dept.empid" :value="dept.empid">{{dept.empname}}</option>
				</select>
			</view><hr>
			<view class="item">
				<text class="text">仓库地址:</text>
				<input type="text1" :disabled="dis" class="text1" v-model="list.adress">
			</view><hr>
			<view class="headbox">
				<text class="text">仓库备注:</text>
				<textarea class="textarea" :disabled="dis" v-model="value"></textarea>
			</view>
			<view v-show="show" class="btnbox">
				<button @click="updata">{{btnname}}</button>
			</view>
		</view>
	</view>
</template> -->

<template>
	<!-- 商品信息 -->
	<view>
		<view class="titlebox">
			<text class="text">{{title}}</text>
			<image v-show="show" @click="updata()" class="img1" src="../../../static/paimg/修改.png" mode=""></image>
			<image v-show="show" @click="delect()" class="img2" src="../../../static/paimg/删除.png" mode=""></image>
		</view>
		<view class="boxcent">
			<view class="box1">
				<text class="text">仓库编号</text>
				<text class="text1">{{list.wid}}</text>
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text">仓库名称</text>
				<text class="text1">{{list.wname}}</text>
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text">仓库负责人:</text>
				<text class="text2">{{dptemname}}</text>
				<select v-show="show" v-model="select">
					<option disabled value="">请选择</option>
					<option v-for="dept in options" :key="dept.empid" :value="dept.empid">{{dept.empname}}</option>
				</select>
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text">仓库地址</text>
				<text class="text1">{{list.adress}}</text>
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text">仓库备注</text>
				<textarea class="textarea" :disabled="dis" v-model="value"></textarea>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title:'仓库信息',data:'',dptemname:'',value:'',btnname:'更新仓库信息',type:true,dis:'false',
				list:{},options:[],select:'',show:true
			}
		},
		onLoad(option) {
			if(option.type !== undefined){
				this.show = false;
			}
			var opt = JSON.parse(option.item)
			this.list = opt;
			this.value = opt.title
			this.getdata();
		},
		methods: {
			async getdata(){
				var emid = this.dptemid;
				const res = await this.Request({
					url:'/api/employee/getdptname',
					method:'POST',
					data:{departmentid:3}
				})
				this.options =res.data
				for(var i=0;i<res.data.length;i++){
					if(res.data[i].empid==this.list.waremid){
						this.dptemname = res.data[i].empname
					}
				}
			},
			async updata(){
				//成员id
				var selectname = this.select; 
				var textarea = this.value;
				this.type = !this.type;
				if(this.type==true){
					// 第二次点击
					this.type =  true;
					this.flag=0;
					const res = await this.Request({
						url:'api/warehouse/upwarpdata',
						method:'PUT',
						data:{wname:this.list.wname,waremid:this.list.waremid,
						adress:this.list.adress,title:textarea,wid:this.list.wid}
					})
					if(res.data.affectedRows = 1){
						uni.showToast({
							title: '更新成功'
						})
						setTimeout(() => {
							uni.navigateBack({
								delta:2
							})
						},500)
					}
				}else{
					// 第一次点击
					this.type =  false;
					this.dis = false;
					this.btnname = "保存"
				}
			},
			delect(e){
				uni.showModal({
					title: '提示',
					content: '是否确认删除此仓库',
					success(res) {
						if (res.confirm) {
							uni.request({
								url:'api/warehouse/wardelect',
								method:'DELETE',
								data:{wid:e},
								success(res){
									setTimeout( () => {
										uni.showToast({
											title: '删除成功',
										})
									},300)
									uni.reLaunch({
										url:'/pages/public/warehouse/warment',
									})
								}
							})
						}
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	.titlebox{
		margin-top: 10px;
		width: 100%;
		height: 30px;
		background-color: #efefef;
		display: flex;
		border-bottom: 1px solid #ccc;
		image{
			margin: auto 0;
			height: 20px;
			width: 20px;
		}
		.text{
			margin: 5px 0 5px 5px;
			font-size: 110%;
			font-weight: 600;
			color: #008300;
		}
		.img1{
			margin-left: 240px;
		}
		.img2{
			margin-left: 10px;
		}
	}
	.imgbox{
		display: flex;
		height: 80px;
		margin-top: 10px;
		border-top: 2px solid #ccc;
		border-bottom: 2px solid #ccc;
		border-radius: 10px;
		.text{
			margin: auto 0;
			margin-left: 10%;
			font-weight: 600;
			font-size: 110%;
		}
		.image{
			margin: auto 0;
			margin-left: 100px;
			height: 60px;
			width: 60px;
		}
	}
	.boxcent{
		margin-top: 10px;
		border-top: 2px solid #ccc;
		border-bottom: 2px solid #ccc;
		border-radius: 10px;
		.br{
			height: 1px;
			margin-left: 10%;
			background: #a5a5a5;
		}
		.box1{
			margin-top: 10px;
			margin-bottom: 10px;
			.text{
				margin-left: 10%;
				font-weight: 600;
				font-size: 110%;
			}
			.text1{
				margin-left: 105px;
			}
			.text2{
				margin-left: 85px;
			}
			.textarea{
				border: 1px solid #d4d4d4;
				border-radius: 10px;
				margin-left: 40px;
				margin-top: 10px;
			}
		}
	}
	.boxhead{
		margin-top: 10px;
		.box{
			border-top: 2px solid #ccc;
			border-bottom: 2px solid #ccc;
			border-radius: 10px;
			.br{
				height: 1px;
				margin-left: 10%;
				background: #a5a5a5;
			}
			.box1{
				margin-top: 10px;
				margin-bottom: 10px;
				.text{
					margin-left: 10%;
					font-weight: 600;
					font-size: 110%;
				}
				.text1{
					margin-left: 105px;
				}
			}
		}
	}
</style>

